package com.cars.phoenix.controller;

import com.cars.phoenix.entity.Student;
import com.cars.phoenix.service.StudentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: StudentController
 * @Description: 学生-业务控制层
 * @author: caoqianfan
 * @date: 2023/9/15 16:00
 */
@RestController
@RequestMapping("/student")
public class StudentController {
    @Resource
    private StudentService studentService;

    @PostMapping("/save")
    public void save(@RequestBody Student student) {
        studentService.upsert(student);
    }

    @DeleteMapping("remove")
    public boolean remove(@RequestParam int id) {
        return studentService.removeById(id);
    }

    @PutMapping("/update")
    public void update(@RequestBody Student student) {
        studentService.upsert(student);
    }

    @GetMapping("/list")
    public List<Student> list() {
        return studentService.list();
    }

    @GetMapping("/listById")
    public Student listById(@RequestParam int id) {
        return studentService.getById(id);
    }
}
